package huixue.cn.com.rxapp.rxjava2;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import huixue.cn.com.rxapp.util.LogUtils;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by gongdongyang 2019/8/12
 * Describe:
 */
public class JsutUtil {

    public static void range(){
        Observable
                .range(2,6)
                .throttleFirst(3, TimeUnit.SECONDS)
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        LogUtils.d("JsutUtil","integer==>:"+integer);
                    }
                });


    }


    public static void doAmb(){
        List<Flowable<Integer>> flowables = new ArrayList<Flowable<Integer>>();

        flowables.add(Flowable.just(20,40,60));

        flowables.add(Flowable.just(1,2,3));

        flowables.add(Flowable.just(0,0,0).delay(1, TimeUnit.SECONDS));

        Flowable
                .amb(flowables)
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        LogUtils.d("JsutUtil","value is " + integer);
                    }
                });
    }
}
